#if !defined(AFX_UNZIPPER_H__EBC42716_31C7_4659_8EF3_9BF8D4409709__INCLUDED_)
#define AFX_UNZIPPER_H__EBC42716_31C7_4659_8EF3_9BF8D4409709__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <Windows.h>
#include <vector>
#include <string>

using namespace std;

const int MAX_COMMENT = 255;

// create our own fileinfo struct to hide the underlying implementation

struct UZ_FileInfo
{
	char szFileName[MAX_PATH + 1];
	char szComment[MAX_COMMENT + 1];

	DWORD dwVersion;  
	DWORD dwVersionNeeded;
	DWORD dwFlags;	 
	DWORD dwCompressionMethod; 
	DWORD dwDosDate;	
	DWORD dwCRC;   
	DWORD dwCompressedSize; 
	DWORD dwUncompressedSize;
	DWORD dwInternalAttrib; 
	DWORD dwExternalAttrib; 
	bool bFolder;
};

class CUnzipper  
{
public:
	CUnzipper(LPCSTR szFilePath = NULL);
	virtual ~CUnzipper();

	// simple interface
	static bool Unzip(LPCSTR szFileName, LPCSTR szFolder = NULL, bool bIgnoreFilePath = FALSE);

	// works with prior opened zip
	bool CustomUnZip(std::vector<const char *> &vtKeyFileName, bool bIgnoreFilePath = false );
	bool UnzipTo(LPCSTR szFolder, std::vector<const char *> &vtKeyFileName, bool bIgnoreFilePath = false ); 

	bool Unzip(const char *sKeyFileName = NULL, bool bIgnoreFilePath = false); // unzips to output folder or sub folder with zip name 
	bool UnzipTo(LPCSTR szFolder, const char *sKeyFileName = NULL, bool bIgnoreFilePath = false ); // unzips to specified folder

	// extended interface
	bool OpenZip(LPCSTR szFilePath);
	bool CloseZip(); // for multiple reuse
	bool SetOutputFolder(LPCSTR szFolder); // will try to create

	// unzip by file index
	int GetFileCount();
	bool GetFileInfo(int nFile, UZ_FileInfo& info);
	bool UnzipFile(int nFile, LPCSTR szFolder = NULL, bool bIgnoreFilePath = FALSE);

	// unzip current file
	bool GotoFirstFile(LPCSTR szExt = NULL);
	bool GotoNextFile(LPCSTR szExt = NULL);
	bool GetFileInfo(UZ_FileInfo& info);
	bool UnzipFile(LPCSTR szFolder = NULL, bool bIgnoreFilePath = FALSE);

	// helpers
	bool GotoFile(LPCSTR szFileName, bool bIgnoreFilePath = TRUE);
	bool GotoFile(int nFile);

protected:
	void* m_uzFile;
	char m_szOutputFolder[MAX_PATH + 1];

protected:
	static bool CreateFolder(LPCSTR szFolder);
	static bool CreateFilePath(LPCSTR szFilePath); // truncates from the last '\'
	static bool SetFileModTime(LPCSTR szFilePath, DWORD dwDosDate);

};

#endif // !defined(AFX_UNZIPPER_H__EBC42716_31C7_4659_8EF3_9BF8D4409709__INCLUDED_)
